package cn.zzf.algs.note.exercise.fundamental;

import edu.princeton.cs.algs4.StdDraw;
import edu.princeton.cs.algs4.StdRandom;

import java.awt.*;

/**
 * @author GaoFeng
 * @date 2019/11/25 14:18
 */
public class Ex1_1_31 {

    public static void main(String[] args) {
        randomConnect();
    }

    public static  void randomConnect() {

        // 随机连接，编写一段程序，从命令行接受一个整数N和double值p(0到1之间)参数, 在一个圆上画出大小为0.05且间距相等的N个点, 然后将每对点按照概率p用灰线连接
        int n = 16;
        int radius = 1000;
        double p = 0.6;

        StdDraw.setCanvasSize(radius, radius);
        StdDraw.setScale(-1.1, 1.1);
        StdDraw.setPenRadius(0.015);
        StdDraw.setPenColor(Color.BLUE);


        // 初始化所有的点
        double[][] d = new double[n][2];
        for (int i = 0; i < n; i++)
        {
            d[i][0] = Math.cos(2 * Math.PI * i / n);
            d[i][1] = Math.sin(2 * Math.PI * i / n);
            StdDraw.point(d[i][0], d[i][1]);
        }

        for (int i = 0;i < d.length - 1;i++) {
            if (StdRandom.bernoulli(p)) {
                StdDraw.line(d[i][0], d[i][1], d[i + 1][0], d[i + 1][1]);
            }
        }

        //
        // for (int i = 0; i < n - 1; i++)
        //     for (int j = i + 1; j < n; j++)
        //         if (StdRandom.bernoulli(p))
        //             StdDraw.line(d[i][0], d[i][1], d[j][0], d[j][1]);

    }
}
